<template>
	<view class="publicList">
		<view class="" v-if="list.length> 0">
			<view class="ListBox" v-for="item in list" :key="item.id">
				<view class="titles">
					<view class="titleBox" v-for="data in title" :key="data.key">
						<text class="name">{{data.label}}：</text>{{item[data.key]}}
					</view>
					<view v-if="isDel" style="text-align: right;">
						<roc-btn type="error" text="删除" @click.native="handleDel(item)"></roc-btn>
					</view>
				</view>
			</view>
		</view>
		<view style="text-align: center;padding-bottom: 50px;" v-else>
			<image src="@/static/img/nullData.png" style="width: 160px;height: 160px;"></image>
			<view class="">
				暂无数据
			</view>
		</view>
		<!-- 删除 -->
		<u-modal :show="modalShow" :showCancelButton="true" title="删除" content="确定删除吗?" @confirm="confirm"
			@cancel="modalShow = false" @close="modalShow = false"></u-modal>
	</view>
</template>

<script>
	import {
		doDel
	} from '@/api/car.js'
	export default {
		data() {
			return {
				title: [],
				list: [],
				isDel: false,
				modalShow: false,
				formId: {}
			}
		},
		methods: {
			showEdit(data) {
				this.title = data.headers
				this.list = data.list
				if (data.type === "isDel") {
					this.isDel = true;
				}
			},
			handleDel(row) {
				this.formId = row;
				this.modalShow = true;
			},
			// 确定删除
			async confirm() {
				const {
					data
				} = await doDel({
					id: this.formId.id
				})
				this.$u.toast(data.msg);
				this.$emit('fetch-data')
				this.modalShow = false;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.publicList {
		.ListBox {
			width: 95%;
			margin: 0 auto;
			margin-top: 20rpx;
			border: 1px solid #ebeef5;
			border-radius: 5px;
			background-color: #fff;
			-moz-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
			-webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
			box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);

			.titles {
				width: 95%;
				margin: 0 auto;
				padding: 20rpx 0;

				.titleBox {
					width: 49%;
					padding: 17rpx 0;
					display: inline-block;
					font-size: 12px;
					color: #999999;

					.name {
						color: #000;
						font-size: 13px;
					}
				}

			}
		}
	}
</style>
